<html>
<head><meta charset="utf-8"><title>catching copy-paste errors · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html">catching copy-paste errors</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223841318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223841318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223841318">(Jan 24 2021 at 23:12)</a>:</h4>
<p>Is there a lint in either the compiler or clippy that could have caught this?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="sd">/// Treat all files as text, disabling binary attributes and detection.</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">force_text</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">force</span>: <span class="kt">bool</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">DiffOptions</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">self</span><span class="p">.</span><span class="n">flag</span><span class="p">(</span><span class="n">raw</span>::<span class="n">GIT_DIFF_FORCE_TEXT</span><span class="p">,</span><span class="w"> </span><span class="n">force</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="sd">/// Treat all files as binary, disabling text diffs</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">force_binary</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">force</span>: <span class="kt">bool</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">DiffOptions</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">self</span><span class="p">.</span><span class="n">flag</span><span class="p">(</span><span class="n">raw</span>::<span class="n">GIT_DIFF_FORCE_TEXT</span><span class="p">,</span><span class="w"> </span><span class="n">force</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="223842884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223842884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223842884">(Jan 24 2021 at 23:43)</a>:</h4>
<p>The issue is that <code>force_binary</code> has the same body as <code>force_text</code>, right?</p>



<a name="223843202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223843202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223843202">(Jan 24 2021 at 23:50)</a>:</h4>
<p>That might be one way to catch this.</p>



<a name="223843227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223843227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223843227">(Jan 24 2021 at 23:51)</a>:</h4>
<p>There are a pile of functions here that all look the same, setting a flag based on a bool argument.</p>



<a name="223843282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223843282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223843282">(Jan 24 2021 at 23:52)</a>:</h4>
<p>Maybe there could be a clippy lint for two (or more) functions with the same arguments, return type, and body, but different names.</p>



<a name="223843289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223843289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223843289">(Jan 24 2021 at 23:52)</a>:</h4>
<p>I can imagine catching this due to identical non-trivial function bodies with different names and doc comments, or due to <code>force_binary</code> not following the pattern...</p>



<a name="223843290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223843290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223843290">(Jan 24 2021 at 23:52)</a>:</h4>
<p>Or something along those lines.</p>



<a name="223843294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223843294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223843294">(Jan 24 2021 at 23:52)</a>:</h4>
<p>You might want to ask in <a class="stream" data-stream-id="257328" href="/#narrow/stream/257328-clippy">#clippy</a>.</p>



<a name="223843299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223843299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223843299">(Jan 24 2021 at 23:52)</a>:</h4>
<p>Will do, thank you.</p>



<a name="223843301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223843301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223843301">(Jan 24 2021 at 23:52)</a>:</h4>
<p>I'm guessing this is too specialized for rustc.</p>



<a name="223843302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223843302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223843302">(Jan 24 2021 at 23:52)</a>:</h4>
<p>Sure! :)</p>



<a name="223843319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223843319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223843319">(Jan 24 2021 at 23:53)</a>:</h4>
<p>Yeah, I figured it was likely too specialized for rustc; I only asked in case there was <em>already</em> something and it wasn't triggering.</p>



<a name="223844061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223844061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223844061">(Jan 25 2021 at 00:06)</a>:</h4>
<p>I don't know of any lint like that and I wouldn't expect there to be one because it's so specialized. But it's possible it's allow-by-default or something :)</p>



<a name="223845947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223845947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223845947">(Jan 25 2021 at 00:50)</a>:</h4>
<p>I can't remember the name of the tool, but there's a C or C++ tool that I think would catch something similar</p>



<a name="223845951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223845951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223845951">(Jan 25 2021 at 00:50)</a>:</h4>
<p>They write blog posts showing examples of running their tool on open source projects.</p>



<a name="223845956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223845956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223845956">(Jan 25 2021 at 00:50)</a>:</h4>
<p>But I can't find one now.</p>



<a name="223845963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223845963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223845963">(Jan 25 2021 at 00:51)</a>:</h4>
<p>coverity, maybe</p>



<a name="223845977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223845977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223845977">(Jan 25 2021 at 00:51)</a>:</h4>
<p>Oh, here it is — <a href="https://www.viva64.com/en/a/0068/">https://www.viva64.com/en/a/0068/</a></p>



<a name="223846040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223846040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223846040">(Jan 25 2021 at 00:52)</a>:</h4>
<p><a href="https://www.viva64.com/en/b/0708/">https://www.viva64.com/en/b/0708/</a></p>



<a name="223898905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/catching%20copy-paste%20errors/near/223898905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/catching.20copy-paste.20errors.html#223898905">(Jan 25 2021 at 13:49)</a>:</h4>
<p><a href="https://www.jetbrains.com/help/idea/analyzing-duplicates.html">https://www.jetbrains.com/help/idea/analyzing-duplicates.html</a> may be able to chat this case.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>